#include <stdio.h>

int leftmost[ 1002 ][ 1002 ], rightmost[ 1002 ][ 1002 ], max, high[ 1002 ][ 1002 ];

int main( )
{
    int n, m, i, j, t, k;
    char map[ 2 ];
    scanf("%d", &t);
    while ( t-- )
    {
        scanf("%d%d", &m, &n);
        max = 0;
        for ( i = 1; i <= m; i++ )
        {
            high[ i ][ 0 ] = high[ i ][ n + 1 ] = -1;
            for ( j = 1; j <= n; j++ )
            {
                scanf("%s", map);
                if ( i == 1 )
                {
                    if ( map[ 0 ] == 'F' ) high[ i ][ j ] = 1;
                    else high[ i ][ j ] = 0;
                }
                else
                {
                    if ( map[ 0 ] == 'F' )
                        high[ i ][ j ] = high[ i - 1 ][ j ] + 1;
                    else high[ i ][ j ] = 0;
                }
            }
        }
        for ( k = 1; k <= m; k++ )
        {
            for ( i = 1; i <= n; i++ )
            {
                j = i;
                leftmost[ k ][ i ] = i - 1;
                while ( high[ k ][ leftmost[ k ][ j ] ] >= high[ k ][ i ] )
                {
                    j = leftmost[ k ][ j ];
                    leftmost[ k ][ i ] = leftmost[ k ][ j ];
                }
            }
        }
        for ( k = 1; k <= m; k++ )
        {
            for ( i = n; i >= 1; i-- )
            {
                j = i;
                rightmost[ k ][ i ] = i + 1;
                while ( high[ k ][ rightmost[ k ][ j ] ] >= high[ k ][ i ] )
                {
                    j = rightmost[ k ][ j ];
                    rightmost[ k ][ i ] = rightmost[ k ][ j ];
                }
            }
        }
        for ( i = 1; i <= m; i++ )
            for ( j = 1; j <= n; j++ )
                if ( max < ( rightmost[ i ][ j ] - leftmost[ i ][ j ] - 1 ) * high[ i ][ j ] )
                    max = ( rightmost[ i ][ j ] - leftmost[ i ][ j ] - 1 ) * high[ i ][ j ];
        printf("%d\n", max * 3);
    }
    return 0;
}
